<template>
  <div class="app-container">
    <div class="clearfix headerTitle">
      <span>{{userName}}</span>
    </div>
    <el-table border :data="tableData.list" v-loading="loading" element-loading-text="加载中..."
              show-summary
              :summary-method="getSummaries"
              class="el-table-align-center">
      <el-table-column label="添加时间" type="time" align="center">
        <template slot-scope="{row}">
          {{row.create_time | toTime}}
        </template>
      </el-table-column>
      <el-table-column label="域名名称" prop="name" align="center">
      </el-table-column>

      <el-table-column label="域名类别" prop="type" align="center">
        <template slot-scope="{row}">
          {{row.type | toConverter('DOMAIN_TYPE')}}
        </template>
      </el-table-column>
      <el-table-column label="链接地址" prop="domain" align="center">
        <template slot-scope="{row}">
          {{Number(row.type) === 1 ? row.domain : 'https://'+row.domain+'.ballbet2.com'}}
        </template>
      </el-table-column>
      <el-table-column label="总注册人数" prop="registerNum" align="center"></el-table-column>
      <el-table-column label="充值总人数" prop="rechargeNum" align="center"></el-table-column>
    </el-table>
  </div>
</template>


<script>
  import {getAgencyDomainListDetail} from "@/services/api/agency";
  import {grid, form, dialog} from '@/build'

  export default {
    name: "domain-list",
    components: {},
    mixins: [grid, form, dialog],
    props: ['userId', 'userName'],
    data() {
      const host = window.location.host.replace(/www/g, '');
      return {
        tableData: [],
        host: host,
        filters: {
          proxyId: 0,

        }
      }
    },
    methods: {
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          const values = data.map(item => Number(item[column.property]));
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          if ([1, 2, 3].indexOf(index) !== -1) {
            sums[index] = '';
            return;
          }
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          })
        })

        return sums
      }
    },
    mounted() {
      this.filters.proxyId = this.userId;
      this.bindGet(getAgencyDomainListDetail, 'tableData', {
        action: 'getGrid',
        sendingData: 'filters',
      });
      this.getAll();
    }
  }
</script>

<style lang="scss" scoped>
  .el-table-align-center {
    &.el-table {
      width: 100%;
      text-align: center !important;
      th {
        text-align: center !important;
      }
    }
  }

</style>
